package cn.kow.kmall.controller;

import cn.kow.kmall.core.constant.KmallStatusConstant;
import cn.kow.kmall.core.response.KmallResult;
import cn.kow.kmall.pojo.dto.ItemListDTO;
import cn.kow.kmall.pojo.dto.ItemQueryDTO;
import cn.kow.kmall.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: lijun
 * @Description:
 * @Date: Created in 2019-05-13 15:27
 * @Modified By:
 */
@Slf4j
@RestController
public class ItemRcmdController {

    @Autowired
    private ItemService itemService;

    /**
     * 首页商品推荐
     * @return
     */
    @GetMapping(value = "/rcmd/index")
    public KmallResult indexRecommend(@PageableDefault Pageable pageable) {
        ItemQueryDTO queryDTO = ItemQueryDTO.builder().status(KmallStatusConstant.NORMAL).build();
        queryDTO.setPage(pageable.getPageNumber());
        queryDTO.setSize(pageable.getPageSize());
        queryDTO.setOrderBy("sort asc");
        List<ItemListDTO> itemList = itemService.queryItemList(queryDTO);
        Map<String, Object> result = new HashMap<>();
        result.put("rcmdItemList", itemList);
        result.put("page", pageable.getPageNumber());
        result.put("size", pageable.getPageSize());
        return KmallResult.success(result);
    }

    /**
     * 购物车商品推荐
     * @return
     */
    @GetMapping(value = "/item/recommend")
    public KmallResult cartRecommend() {
        ItemQueryDTO queryDTO = ItemQueryDTO.builder().status(KmallStatusConstant.NORMAL).build();
        queryDTO.setPage(1);
        queryDTO.setSize(20);
        queryDTO.setOrderBy("sort asc");
        List<ItemListDTO> itemList = itemService.queryItemList(queryDTO);
        return KmallResult.success().put("desc", "猜你喜欢").put("itemList", itemList);
    }
}
